package com.evil.common.account.enums;

import com.evil.common.core.enums.BaseEnum;
import com.evil.common.family.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 应用服务类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum AppTypeEnum {

    /**
     * 应用服务类型
     */
    ADMIN(1, "总后台权限设置", "/admin"),
    ENTERPRISE(2, "企业后台权限设置", "/enterprise"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;
    @Getter
    private final String basePath;

    public static Optional<AppTypeEnum> findById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> id.equals(e.getId())).findFirst();
    }

    public static AppTypeEnum isExistById(Integer id) {
        return AppTypeEnum.findById(id).orElseThrow(() -> new BusinessException(BaseEnum.ERROR_PARAMETER, "应用类型错误"));
    }

}
